
//
//  MCMMPopView.m
//  TLYL
//
//  Created by miaocai on 2017/10/20.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCMMPopView.h"
@interface MCMMPopView()

@end

@implementation MCMMPopView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpUI];
        self.userInteractionEnabled = YES;
    }
    return self;
}
- (void)setUpUI{

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy/MM/dd"];
    
    self.frame = CGRectMake(0, 0, G_SCREENWIDTH, G_SCREENHEIGHT - kTabBarHeight);
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(13, 13 +kStatusBarAndNavigationBarHeight, G_SCREENWIDTH - 26, 150)];
    [self addSubview:bgView];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 6;
    bgView.clipsToBounds = YES;
  

    UIView *bgViewTitle = [[UIView alloc] initWithFrame:CGRectMake(0, 0, G_SCREENWIDTH - 26, 49.5)];
    bgViewTitle.tag = 1004;
    [bgView addSubview:bgViewTitle];
    bgViewTitle.backgroundColor = [UIColor whiteColor];
    [bgViewTitle addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgViewTitleClick)]];
    
    UILabel *titleLab =[[UILabel alloc]init];
    titleLab.textColor=RGB(46, 46, 46);
    titleLab.font=[UIFont systemFontOfSize:14];
    titleLab.text =@"会员名称";
    titleLab.textAlignment=NSTextAlignmentCenter;
    [bgViewTitle  addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView).offset(11);
        make.left.equalTo(bgView).offset(11);
        make.height.equalTo(@(38));
        
    }];
    UITextField  *tf=[[UITextField alloc]init];
    [bgViewTitle addSubview:tf];
    self.tf = tf;
    
    tf.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入用户名称" attributes:@{NSForegroundColorAttributeName:RGB(181, 181, 181),NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(14)]}];
    tf.textAlignment = NSTextAlignmentRight;
    
    
    [tf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-30));
        make.centerY.equalTo(titleLab);
        make.width.equalTo(@(MC_REALVALUE(129)));
    }];
    
    UIView *line1 = [[UIView alloc] init];
    line1.backgroundColor = RGB(213, 213, 213);
    [bgViewTitle addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@0.5);
        make.top.equalTo(bgViewTitle.mas_bottom);
        make.right.left.equalTo(bgViewTitle);
    }];
    
    UIView *bgViewStart = [[UIView alloc] initWithFrame:CGRectMake(0, 50, G_SCREENWIDTH - 26, 49.5)];
    [bgView addSubview:bgViewStart];
    bgViewStart.tag = 1003;
    [bgViewStart addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgViewStartClick)]];
    bgViewStart.backgroundColor = [UIColor whiteColor];
    
    UILabel *startDateLab =[[UILabel alloc]init];
    startDateLab.textColor=RGB(46, 46, 46);
    startDateLab.font=[UIFont systemFontOfSize:14];
    startDateLab.text =@"开始时间";
    startDateLab.textAlignment=NSTextAlignmentCenter;
    [bgViewStart addSubview:startDateLab];
    
    [startDateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLab.mas_bottom).offset(11);
        make.left.equalTo(titleLab);
        make.height.equalTo(@(38));
    }];
    UIView *line3 = [[UIView alloc] init];
    line3.backgroundColor = RGB(213, 213, 213);
    [bgViewStart addSubview:line3];
    [line3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@0.5);
        make.top.equalTo(bgViewStart.mas_bottom);
        make.right.left.equalTo(bgViewStart);
    }];

    UILabel *startDateLabDetail =[[UILabel alloc]init];
    startDateLabDetail.textColor=RGB(102, 102, 102);
    startDateLabDetail.font=[UIFont systemFontOfSize:14];
//    startDateLabDetail.text =endDateStr;
    startDateLabDetail.textAlignment=NSTextAlignmentRight;
    [bgViewStart  addSubview: startDateLabDetail];
    
    
    
    [startDateLabDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-30));
        make.centerY.equalTo(startDateLab);
        make.width.equalTo(@(MC_REALVALUE(129)));
    }];
    
    
    UIImageView *imgVs = [[UIImageView alloc] init];
    imgVs.image = [UIImage imageNamed:@"MC_right_arrow"];
    [bgViewStart addSubview:imgVs];
    [imgVs mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgViewStart.mas_right).offset(-15);
        make.centerY.equalTo(startDateLab);
    }];
    
    UIView *bgViewEnd = [[UIView alloc] initWithFrame:CGRectMake(0, 100, G_SCREENWIDTH - 26, 49.5)];
    [bgView addSubview:bgViewEnd];

    bgViewEnd.tag = 1002;
    [bgViewEnd addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgViewEDNClick)]];
    bgViewEnd.frame = CGRectMake(0, 100, G_SCREENWIDTH - 26, 49.5);


    UILabel  *endDateLab =[[UILabel alloc]init];
    endDateLab.textColor=RGB(46, 46, 46);
    endDateLab.font=[UIFont systemFontOfSize:14];
    endDateLab.text =@"结束时间";
    endDateLab.textAlignment=NSTextAlignmentCenter;
    [bgViewEnd  addSubview:endDateLab];
    
    [endDateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(startDateLab.mas_bottom).offset(11);
        make.left.equalTo(titleLab);
        make.height.equalTo(@(38));
        
    }];
    
    UILabel  *endDateLabDetail =[[UILabel alloc]init];
    endDateLabDetail.textColor=RGB(102, 102, 102);
    endDateLabDetail.font=[UIFont systemFontOfSize:14];
//    endDateLabDetail.text =endDateStr;
    endDateLabDetail.textAlignment=NSTextAlignmentRight;
    [bgViewEnd  addSubview: endDateLabDetail];
    
    [endDateLabDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-30));
        make.centerY.equalTo(endDateLab);
        make.width.equalTo(@(MC_REALVALUE(129)));
        
    }];
    
    UIImageView *imgVe = [[UIImageView alloc] init];
    imgVe.image = [UIImage imageNamed:@"MC_right_arrow"];
    [bgViewEnd addSubview:imgVe];
    [imgVe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgVs);
        make.centerY.equalTo(endDateLab);
    }];
    
    
    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:@"立即搜索" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
    [self addSubview:btn];
    btn.backgroundColor = MC_THEME_COLOR;
    btn.layer.cornerRadius = 6;
    btn.clipsToBounds = YES;
    [btn addTarget:self action:@selector(searchBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(bgView);
        make.height.equalTo(@(40));
        make.top.equalTo(bgView.mas_bottom).offset(10);
    }];
    self.hidden = YES;
    
 
    self.startDateLabDetail = startDateLabDetail;
    self.endDateLabDetail = endDateLabDetail;
    


}





- (void)bgViewStartClick{
    [self.tf resignFirstResponder];
    if (self.startDateBlock) {
        self.startDateBlock();
    }
}
- (void)bgViewEDNClick{
    [self.tf resignFirstResponder];
    if (self.endDateBlock) {
        self.endDateBlock();
    }
}

- (void)bgViewTitleClick{
    [self.tf resignFirstResponder];
    if (self.lotteryBlock) {
        self.lotteryBlock();
    }
}

- (void)searchBtnClick{
    [self.tf resignFirstResponder];
    if (self.searchBtnBlock) {
        self.searchBtnBlock(self.tf.text);
    }
    self.hidden = YES;
}
- (void)showPopView{
    
    self.hidden = NO;
    
}
- (void)hidePopView{
    
    [UIView animateWithDuration:0.1  animations:^{
        
        self.transform = CGAffineTransformIdentity;
        
    } completion:^(BOOL finished) {
        self.hidden = YES;
        
    }];
}
@end








